package com.soil.code.generation.database.mysql.repository;

import com.soil.code.generation.database.model.TableInfo;
import com.soil.code.generation.database.mysql.repository.po.MysqlTableInfoPO;
import com.soil.code.generation.database.mysql.repository.mapper.MysqlTablesViewMapper;
import com.soil.code.generation.database.repository.TableInfoRepository;
import com.ssy.gaea.common.collection.CollectionUtils;

import java.util.List;

/**
 * @author zeno
 */
public class MysqlTableInfoRepository implements TableInfoRepository{

  private MysqlTablesViewMapper mapper;

  public MysqlTableInfoRepository(MysqlTablesViewMapper mapper ){
    this.mapper = mapper;
  }

  @Override
  public List<TableInfo> findTables( String databaseName ){
    List<MysqlTableInfoPO> tableInfos = mapper.findTableInfos(databaseName);
    return CollectionUtils.convert(tableInfos,MysqlTableInfoRepository::createTableInfo);
  }

  public static TableInfo createTableInfo( MysqlTableInfoPO po ){

    TableInfo tableInfo = new TableInfo();
    tableInfo.setName(po.getTableName());
    tableInfo.setComment(po.getComment());
    return tableInfo;
  }

  @Override
  public List<TableInfo> findTables( List<String> tableNames ){
    return null;
  }
}
